package cn.initcap.elasticjob.job;

import cn.initcap.elasticjob.autoconfig.ElasticSimpleJob;
import cn.initcap.elasticjob.service.OrderService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author initcap
 * @date 6/26/19 3:32 PM
 */
@Slf4j
@ElasticSimpleJob(
        jobName = "mySimpleJob",
        cron = "0/5 * * * * ?",
        shardingTotalCount = 2,
        overwrite = true
)
public class MySimpleJob implements SimpleJob {
    private static final int ORDER_INSERT_SIZE = 10;
    @Autowired
    private OrderService orderService;

    @Override
    public void execute(ShardingContext shardingContext) {

        for (int i = 0; i < ORDER_INSERT_SIZE; i++) {
            orderService.insertOrder();
        }

    }
}
